package com.cloudwise.controller;

import com.cloudwise.entity.*;
import com.cloudwise.service.CustomService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Custom)表控制层
 *
 * @author makejava
 * @since 2020-12-23 14:56:49
 */
@Controller
@RequestMapping("custom")
public class CustomController  extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private CustomService customService;


    /**
     * @create by: Teacher陈
     * @description: 跳转到显示所有客户页面
     * @create time: 2020/12/23 16:02
     * @return
     */
    @GetMapping("toShowCustom")
    public ModelAndView toShowCustom(ModelAndView modelAndView){
        modelAndView.setViewName("custom/showCustom");
        return modelAndView;
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Custom selectOne(Integer id) {
        return this.customService.queryById(id);
    }


    /**
     * create by: Teacher陈
     * description: 条件查询加分页
     * create time: 2020/7/20 17:20

     */
    @RequestMapping("/selectAllCustom")
    @ResponseBody
    public ReturnBean selectAllCustom(PageBean pageBean, Custom custom ){
        //计算分页参数
        int offset = calcPageParam(pageBean);
        List<Custom> customList = customService.queryAllCustomVoByConditionAndLimit(custom,offset, pageBean.getLimit());
        long count = customService.getCount(custom);
        //返回json结果
        ReturnBean returnBean = returnSuccess(customList);
        returnBean.setCount(count);
        return returnBean;

    }
}